Skip to content

Make no_mangle on foreign items explicit instead of implicit #144678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025

Conversation

jdonszelmann
Copy link
Contributor

@jdonszelmann jdonszelmann commented Jul 30, 2025

for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: no_no_mangle or something silly like that but by explicitly putting no_mangle in the codegen fn attrs of foreign items we can default it to no_mangle and then easily remove it when we don't want it.

I guess you'd know about this r? @bjorn3. Shouldn't be too hard to review :)

Builds on #144655 which should merge first.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@bjorn3
Copy link
Member

bjorn3 commented Jul 30, 2025

Can you please squash the last two commits?

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

Can do

@jdonszelmann jdonszelmann force-pushed the no-mangle-extern branch 2 times, most recently from 1790424 to 5240989 Compare July 30, 2025 21:37
@@ -192,6 +192,10 @@ impl CodegenFnAttrs {
/// * `#[export_name(...)]` is present
/// * `#[linkage]` is present
///
/// Note that this returns true for foreign items.
/// However, in some places that care about `contains_extern_indicator`, foreign items
/// (in an `extern` block) should explicitly be ignored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this not return true for foreign items? Foreign items don't need to be exported and the point of this method is to check if an item needs to be exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's annoying since we don't have a did or TyCtxt here. We could, but that'd involve adding another flag in the codegen fn attributes. I decided against that but it's perfectly possible.

@bjorn3
Copy link
Member

bjorn3 commented Aug 1, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 1, 2025

📌 Commit 9003a3b has been approved by bjorn3

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 3, 2025
…jorn3

Make no_mangle on foreign items explicit instead of implicit

for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: `no_no_mangle` or something silly like that but by explicitly putting `no_mangle` in the codegen fn attrs of foreign items we can default it to `no_mangle` and then easily remove it when we don't want it.

I guess you'd know about this r? `@bjorn3.` Shouldn't be too hard to review :)

Builds on rust-lang#144655 which should merge first.
bors added a commit that referenced this pull request Aug 3, 2025
Rollup of 13 pull requests

Successful merges:

 - #143857 (Port #[macro_export] to the new attribute parsing infrastructure)
 - #144070 (Implement `hash_map` macro )
 - #144322 (Add lint against dangling pointers from local variables)
 - #144667 (`AlignmentEnum` should just be `repr(usize)` now)
 - #144678 (Make no_mangle on foreign items explicit instead of implicit)
 - #144790 (Multiple bounds checking elision failures)
 - #144794 (Port `#[coroutine]` to the new attribute system)
 - #144805 (compiletest: Preliminary cleanup of `ProcRes` printing/unwinding)
 - #144808 (`Interner` arg to `EarlyBinder` does not affect auto traits)
 - #144816 (Update E0562 to account for the new impl trait positions)
 - #144822 (Return a struct with named fields from `hash_owner_nodes`)
 - #144824 (Updated test links in compiler)
 - #144829 (Use full flag name in strip command for Darwin)

r? `@ghost`
`@rustbot` modify labels: rollup
@Zalathar
Copy link
Contributor

Zalathar commented Aug 3, 2025

Trying to diagnose rollup failure #144846 (comment)

@bors try jobs=test-various

@rust-bors
Copy link

rust-bors bot commented Aug 3, 2025

⌛ Trying commit 9003a3b with merge 50d1271

To cancel the try build, run the command @bors try cancel.

rust-bors bot added a commit that referenced this pull request Aug 3, 2025
Make no_mangle on foreign items explicit instead of implicit

try-job: test-various
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 3, 2025

💔 Test failed (CI). Failed jobs:

@Zalathar
Copy link
Contributor

Zalathar commented Aug 3, 2025

@bors r-

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 3, 2025
@jdonszelmann
Copy link
Contributor Author

@bors2 try jobs=test-various

rust-bors bot added a commit that referenced this pull request Aug 11, 2025
Make no_mangle on foreign items explicit instead of implicit

try-job: test-various
@rust-bors
Copy link

rust-bors bot commented Aug 11, 2025

⌛ Trying commit 5aa8fb1 with merge b47c284

To cancel the try build, run the command @bors try cancel.

@rust-bors
Copy link

rust-bors bot commented Aug 11, 2025

☀️ Try build successful (CI)
Build commit: b47c284 (b47c28460e3041feeec2dd6f6fcfb2ddc7bf294e, parent: 577166503aee7290e09374da21f4045c455acfd5)

@jdonszelmann
Copy link
Contributor Author

@bjorn3 that seems promising?

@jdonszelmann
Copy link
Contributor Author

@bors2 try jobs=test-various

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 12, 2025
Make no_mangle on foreign items explicit instead of implicit

try-job: test-various
@rust-bors
Copy link

rust-bors bot commented Aug 12, 2025

☀️ Try build successful (CI)
Build commit: a1039d3 (a1039d3cbd63a0b67b7310bc436492f1055f7702, parent: a1531335fe2807715fff569904d99602022643a7)

@jdonszelmann
Copy link
Contributor Author

@bjorn seems ok?

@jdonszelmann
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 12, 2025
@bjorn3
Copy link
Member

bjorn3 commented Aug 12, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 12, 2025

📌 Commit 7aa8707 has been approved by bjorn3

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 12, 2025
@bors
Copy link
Collaborator

bors commented Aug 12, 2025

⌛ Testing commit 7aa8707 with merge 8e62bfd...

@bors
Copy link
Collaborator

bors commented Aug 12, 2025

☀️ Test successful - checks-actions
Approved by: bjorn3
Pushing 8e62bfd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 12, 2025
@bors bors merged commit 8e62bfd into rust-lang:master Aug 12, 2025
12 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 12, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing d9dba3a (parent) -> 8e62bfd (this PR)

Test differences

Show 4 test diffs

4 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 8e62bfd311791bfd9dca886abdfbab07ec54d8b4 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-1: 7151.0s -> 10604.1s (48.3%)
  2. x86_64-apple-2: 4279.4s -> 5341.4s (24.8%)
  3. pr-check-2: 2178.7s -> 2596.1s (19.2%)
  4. aarch64-gnu-llvm-19-2: 2237.2s -> 2639.2s (18.0%)
  5. dist-apple-various: 3911.0s -> 4436.4s (13.4%)
  6. x86_64-rust-for-linux: 2620.5s -> 2939.6s (12.2%)
  7. x86_64-gnu-llvm-19: 2441.7s -> 2738.6s (12.2%)
  8. x86_64-gnu-tools: 3288.6s -> 3666.9s (11.5%)
  9. aarch64-gnu-debug: 4455.3s -> 4961.8s (11.4%)
  10. i686-gnu-nopt-1: 7275.8s -> 8053.4s (10.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8e62bfd): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.6%] 8
Regressions ❌
(secondary)
0.2% [0.1%, 0.5%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.6%] 8

Max RSS (memory usage)

Results (primary -1.3%, secondary 2.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.3% [-1.3%, -1.3%] 1

Cycles

Results (secondary 3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 464.325s -> 465.671s (0.29%)
Artifact size: 377.45 MiB -> 377.43 MiB (-0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Aug 12, 2025
@jdonszelmann
Copy link
Contributor Author

sigh, ye that's significant I'm afraid :/

@@ -443,6 +443,27 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
if tcx.should_inherit_track_caller(did) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
}

// Foreign items by default use no mangling for their symbol name.
if tcx.is_foreign_item(did) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the extra query call here is the cause for the perf regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants